package com.axon.mvc.patterns.proxy
{
	import com.axon.base.helpers.AxReflectionUtils;
	import com.axon.mvc.helpers.AxMvcUtils;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;

	public class AxProxy extends Proxy implements IProxy
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function AxProxy( proxyName: String = null, data: Object = null )
		{
			if ( !proxyName || (proxyName == "") )
				proxyName = AxReflectionUtils.getClassNameByInstance(this);
				
			super(proxyName, data);
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		protected function reportSuccess( requestName: String, body: Object = null, extraInfo: Object = null ): void
		{
			var noteName: String = (AxReflectionUtils.getClassNameByInstance(this) == AxMvcUtils.TERM_SESSION_PROXY) ?	
									requestName + AxMvcUtils.SUFIX_SUCCESS :
									AxMvcUtils.getProxyPrefixName(this) +
								 		AxMvcUtils.removeAxVerbPrefix(requestName) +
								 		AxMvcUtils.SUFIX_SUCCESS;
			
			facade.sendNotification(noteName, { sender: this, body: body, extraInfo: extraInfo });
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		protected function reportFailure( requestName: String, body: Object = null, extraInfo: Object = null ): void
		{
			var noteName: String = (AxReflectionUtils.getClassNameByInstance(this) == AxMvcUtils.TERM_SESSION_PROXY) ?	
									requestName + AxMvcUtils.SUFIX_FAILURE :
									AxMvcUtils.getProxyPrefixName(this) +
								 		AxMvcUtils.removeAxVerbPrefix(requestName) +
										AxMvcUtils.SUFIX_FAILURE;
			
			facade.sendNotification(noteName, { sender: this, body: body, extraInfo: extraInfo });
		}

	}
}